import json
import requests
import time
from urllib3.exceptions import InsecureRequestWarning
import datetime

today = datetime.date.today()  # 今天
yester = today - datetime.timedelta(days=1)
# 禁用安全请求警告
Platform = "掌中云1_夜魅小说网"


def zhangzhongyun1():
    try:
        requests.urllib3.disable_warnings(InsecureRequestWarning)
        r = requests.session()
        url = "https://inovel.818tu.com/login/dologin"
        date = {
            "name": "",
            "password": "",
            "csessionid": "",
            "sig": "",
            "token": "",
            "scene": ""
        }
        rr = r.post(url=url, data=date, verify=False, timeout=15)
        aa = r.get(url="https://inovel.818tu.com/backend/order_stats/api_get_daily_stats/?limit=30", verify=False,
                   timeout=15)
        html = json.loads(aa.text)
        for y in range(len(html)):
            date_date = time.strftime('%Y-%m-%d', time.localtime(int(html[y]["date"])))
            if str(date_date) == str(yester):
                Amount_share = round(int(html[y]["paid_amount"]) / 100 * 0.9, 2)
                date_time = str(yester)
                return date_time, Amount_share, Platform
            else:
                if y == len(html) - 1:
                    return '', 'None', Platform
                else:
                    pass
    except Exception:
        print("获取 掌中云1_夜魅小说网 数据失败")
        return '', 'None', Platform
    except ConnectionError:
        print("获取 掌中云1_夜魅小说网 数据 超时")
        return '', 'None', Platform
